<?php
// +----------------------------------------------------------------------
// | OneKeyAdmin [ Believe that you can do better ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2023 http://onekeyadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: MUKE <513038996@qq.com>
// +----------------------------------------------------------------------
namespace plugins\userinvite\api\controller;

use app\api\BaseController;
use plugins\userinvite\api\model\UserInvite;
/**
 * 邀请好友
 */
class User extends BaseController
{
    /**
     * 用户权鉴
     */
    public $middleware = [\app\api\middleware\AuthCheck::class];
    
    /**
     * 邀请好友注册
     */
    public function index()
    {
        if ($this->request->isPost()) {
            $input     = input('post.');
            $where[]   = ['my', '=', $this->request->userId];
            $inviteUrl = index_url('login/register', ['uid' => $this->request->userId]);
            $count = UserInvite::where($where)->count();
            $data  = UserInvite::where($where)->with(['to'])->order('create_time', 'desc')->page($input['page'], 15)->select();
            return json(['status'=>'success','message'=>'查询成功', 'data' => $data, 'count' => $count, 'url' => $inviteUrl]);
        }
    }
}